﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;
using Microsoft.Win32;
using System.Threading.Tasks;

namespace GW2_Marketeer__WPF_.Commands
{
    public class OpenXMLCommand : ICommand
    {
        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;

        private void doWork(string filename)
        {
            Marketeer.Instance.ImportXMLData(filename);
        }

        public void Execute(object parameter)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "xml files (*.xml)|*.xml|All file (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() ?? false)
            {
                var dialogTask = Task.Factory.StartNew(() => doWork(dlg.FileName));
            }
        }
    }
}
